package ru.incoremedia.gwttest.application.client.view.user.notespage;

import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.PopupPanel;


class MyPanel extends FlowPanel {
    public MyPanel() {
        addHandler(new MouseMoveHandler() {
            @Override
            public void onMouseMove(MouseMoveEvent event) {
                PopupWidget.show(event.getClientX(), event.getClientY());
            }
        }, MouseMoveEvent.getType());        
    }
}

public class PopupWidget  {

    public static PopupPanel p = new PopupPanel(false, false);

    static private int x;

    static private int y;

    public static void setWidget(Composite widget, String width) {
        MyPanel myPanel = new MyPanel();
        myPanel.add(widget);
        myPanel.setWidth(width);
        p.setWidget(myPanel);
    }

    public static void show(int _x, int _y) {
        x = _x;
        y = _y;
        p.setPopupPosition(x + 30 + Window.getScrollLeft(), y + Window.getScrollTop());
        p.show();
    }

    public static void hide() {
        p.clear();
        p.hide();
    }

    public static int getX() {
        return x;
    }

    public static int getY() {
        return y;
    }
}
